<style lang="scss">
  @import 'index';
</style>
<style type="text/css">
  .btn.orange{padding:5rpx 20rpx;font-size: 22rpx
}
</style>
<template>
  <div class="ga-container">
    <div class="ga-product-fresh">
      <div class="banner">
        <img mode="widthFix" src="http://ga-1255639017.file.myqcloud.com/images/shop/banner3.jpg" alt="">
      </div>
      <ul class="ga-group-list ga-media-list">
        <li v-for="(item,index) in data" :key="index">
          <a class="item" href="#">
            <div class="item-media">
              <image class="img-box" mode="aspectFill" :src="item.icon"></image>
            </div>
            <div class="item-inner">
              <p class="title">{{item.goods_name}}</p>
              <p class="p1">{{item.goods_text}}</p>
              <p class="p2">限量{{item.goods_number}}件 ▏{{item.advtime}}开始</p>
              <p class="p3">
                ¥ {{item.shop_price}}
                <span>¥ {{item.market_price}}</span>
              </p>
              <form @submit="formSubmit" :report-submit="true" v-if="item.adv == false">
                <input name="id" :hidden="true" :value="item.id" />
                <button class="btn orange" formType="submit"> <i class="icon-clock-o mr10"></i>提醒我</button>
              </form>
              <button class="btn orange cancel" v-else @click="checl(item.id)">取消提醒</button>
              <!--取消提醒-->
              <!--<div class="btn orange cancel">取消提醒</div>-->
            </div>
          </a>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import {isLogin} from '@/utils/handleLogin'
export default {
  data () {
    return {
       data: [],
       isSet: true
    }
  },
  methods: {
      async load () {
         this.$_util.ajax.post('https://guo-a.com/mapi/adv/getlist?token=' + this.$store.state.Token).then((res)=>{
           console.log(res)
           if(res.code === 200){
              this.data = res.data
           }
         })
      },
      async checl (id) {
         if(!this.isSet){
            return false
          }
          this.isSet = false
          let params = {
             id: id
          }
          this.$_util.ajax.post('https://guo-a.com/mapi/adv/checl?token=' + this.$store.state.Token,params).then((res)=>{
             this.isSet = true
             if(res.code === 200){
                this.data.forEach(item=>{
                   if(item.id == id){
                    item.adv = false
                   }
                 })
             }
          })
      },
      async formSubmit (e) {
          let params = e.mp.detail.value
          params.formid = e.mp.detail.formId
          if(!this.isSet){
            return false
          }
          this.isSet = false
          this.$_util.ajax.post('https://guo-a.com/mapi/adv/createadv?token=' + this.$store.state.Token,params).then((res)=>{
             this.isSet = true
             if(res.code === 200){
               
               this.data.forEach(item=>{
                 if(item.id == params.id){
                  item.adv = true
                 }
               })
             }
          })
      }
  },

  created () {

  },
  onShow () {
     isLogin(()=>{
       this.load()
     })
  }
}
</script>
